<?php
namespace Admin\Controller;
use Think\Controller;


class InfoController extends Controller {

    public function artadd(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        if (!IS_POST) {
            $catModel = D('cat');
            $cid      =  I('cid');
            $cats     =  $catModel->select();
            $this->assign('cats',$cats);
            $this->assign('cid',$cid);
            $this->display();
        }else{
            $artModel=D('article');
            $_POST['is_del']=0;
            $_POST['ctime']=time();
            $_POST['utime']=time();
            if ($artModel->add($_POST)) {
                $this->success("添加成功",(U('Admin/art/artlist',['cid'=>$_POST['cid']])));
            }else{
                $this->error("添加失败");
            }
        }
    }
    public function infolist(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        $where['type'] = I('type');
        $artModel = D('info');
        $count = $artModel->where($where)->count();
        $Page  = new \Think\Page($count,10);
        $arts = $artModel->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();
        $show = $Page->show();
        $this->assign('page',$show);
        $this->assign('type',$where['type']);
        $this->assign('arts',$arts);
        $this->display();
    }

    public function infoedit(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        $infoModel = D('info');
    	if (!IS_POST) {
            $id = I('id');
            $info  = $infoModel->find($id);
            $this->assign('info',$info);
            $this->display();
    	}else{
            $infoModel->cid=$_POST['id'];
            $infoModel->title=$_POST['title'];
            $infoModel->img=$_POST['pic1'];
            $infoModel->file=$_POST['file'];
            if ($infoModel->where('id='.$_POST['id'])->save()) {
                $this->success("修改成功",(U('Admin/info/infolist',['type'=>$_POST['type']])));
            }else{
                $this->error("修改失败");
            }
        }
    }
    public function del(){
        if (!checkCookie()) {       
            $this->redirect('Admin/Index/login');
        }
        $aid = I('get.id');
        $res = M('article')->delete($aid);
        if ($res) {
            $this->success('删除成功',(U('Admin/art/artlist')));
        }else{
            $this->error('删除失败');
        }
    }
    public function ueditor(){
        $data = new \Org\Util\Ueditor();
        echo $data->output();
    }
    public function foud(){
        $foudModel = D('foud');
        if(!empty($_POST)){
             $data = $foudModel->create();
            if($foudModel->where('fid='.$_POST['fid'])->save()){
                 $this->success("修改成功",redirect(U('Admin/art/foud')));
            }else{
                $this->error('修改失败'); 
            }
        }
        $foud = $foudModel->find('1');
        $this->assign('foud',$foud);
        $this->display();
    }
    public function videoadd(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        if (!IS_POST) {
            $catModel = D('cat');
            $cid      =  I('cid');
            $cats     =  $catModel->select();
            $this->assign('cats',$cats);
            $this->assign('cid',$cid);
            $this->display();
        }else{
            $artModel=D('article');
            $_POST['is_del']=0;
            $_POST['ctime']=time();
            $_POST['utime']=time();
            if ($artModel->add($_POST)) {
                $this->success("添加成功",(U('Admin/art/artlist',['cid'=>$_POST['cid']])));
            }else{
                $this->error("添加失败");
            }
        }
    }
}